const fetch = require('node-fetch')
const url = "http://nc.mofcom.gov.cn/jghq/priceList"
const exampleData = { pageSize: 10, orderBy: "GET_P_DATE", pageNo: 1, craftName: "柠檬", eudName: '甘肃酒泉春光农产品市场', queryDateType: 0, timeRange: "2020-07-01+~+2020-11-14", sortColumns: `[{"column":"GET_P_DATE","ordername":"asc"}]` }
const configs = {
  headers: {
    "accept": "application/json, text/javascript, */*; q=0.01",
    "accept-language": "zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6",
    "cache-control": "no-cache",
    "content-type": "application/x-www-form-urlencoded; charset=UTF-8",
    "pragma": "no-cache",
    "x-requested-with": "XMLHttpRequest",
    // "cookie": "insert_cookie=28314071"
  },
  // referrer: "http://nc.mofcom.gov.cn/jghq/marketDetail?eudId=45807",
  // referrerPolicy: "strict-origin-when-cross-origin",
  method: "POST",
  mode: "cors"
}
/**
 * 
 * @param {Number} pageNo 
 * @param {Number} pageSize 
 * @param {String} orderBy 
 * @param {String} craftName 
 * @param {String} eudName 
 * @param {String} queryDateType 
 * @param {String} timeRange 
 * @param {String} sortColumns 
 * @returns 
 * {
    pageNo: 1,
    pageSize: 10,
    orderBy: null,
    order: 'desc',
    autoCount: true,
    result: [{
        AG_PRICE: 5,
        CRAFT_NAME: '富士苹果',
        C_UNIT: '元/公斤',
        GET_P_DATE: 1625500800000,
        CRAFT_INDEX: '13097',
        PAR_INDEX: 13076,
        PROMULGATE_DATE: 1625558130000,
        ID: 15001931,
        P_INDEX: '620901',
        EUD_PIC: '/files/eud_project/2012/04/19/1334820492743.jpg',
        EUD_NAME: '甘肃酒泉春光农产品市场'
    }],
    totalCount: 6,
    totalPageCount: 1,
    orderBySetted: false,
    totalPages: 1,
    hasNext: false,
    nextPage: 1,
    hasPre: false,
    prePage: 1,
    first: 1
  } 
 */
async function getPriceListByName({ pageSize = 2, orderBy = "GET_P_DATE", pageNo = 1, craftName = "柠檬", eudName = '甘肃酒泉春光农产品市场', queryDateType = 0, timeRange = "2020-07-01+~+2020-11-14", sortColumns = `[{"column":"GET_P_DATE","ordername":"asc"}]` }={}) {
  const res = await fetch(url, {
    ...configs,
    body: `orderBy=${orderBy}&pageSize=${pageSize}&pageNo=${pageNo}&craftName=${craftName}&eudName=${eudName}&queryDateType=${queryDateType}&timeRange=${timeRange}&sortColumns=${sortColumns}`,
  }).then(res => res.json());
  console.log(res);
  return res;
}
getPriceListByName()